﻿using UnityEngine;
using System.Collections;

public class Enemy : Unit {

	public Enemy_Type type;//敌人的累心
	public Vector2 range;//敌人出生的上下范围
	public float power;//撞到敌人的伤害

    protected override void Start()
    {
        base.Start();
        transform.localPosition = new Vector3 (0, Random.Range (range.x, range.y), 0);
		Fly ();
		Destroy (gameObject, 5f);
    }
	
	
	void Update () {
        //Swing类型的怪会上下移动
		if (type == Enemy_Type.Swing) 
		{
			transform.position+=new Vector3(0,Mathf.Sin(Time.time*5f)/10,0);
		}
		transform.position += new Vector3 (-speed * Time.deltaTime, 0, 0);
		fireTimer += Time.deltaTime;
		Fire ();
	}
 

    void OnTriggerEnter2D(Collider2D other)
	{
        //玩家子弹
		if (other.gameObject.tag=="Bullet") 
		{
			Bullet b=other.GetComponent<Bullet>();
			hp-=b.power;
			Destroy(other.gameObject);
		}
        //玩家
		if (other.gameObject.tag=="Player") 
		{
			hp=0;
		}
		Death();
	}
}
